Page({

  /**
   * 页面的初始数据
   */
  data: {
    barMarginTop: '16',
    barHeight: '52',
    barWidth: '0',
    scrollHeight: '',
    x: 0,
    y: 0,
    list: [
      {url: '/images/1.png', translateX: 0, translateY: 0, translateZ: -50, scale: 1, rotate: 0, zIndex: 4, isGoback: false},
      {url: '/images/2.png', translateX: 0, translateY: 16, translateZ: -50, scale: 0.95, rotate: 0, zIndex: 2, isGoback: false},
      {url: '/images/3.png', translateX: 0, translateY: 32, translateZ: -50, scale: 0.9, rotate: 0, zIndex: 1, isGoback: false},
      {url: '/images/4.png', translateX: 0, translateY: 32, translateZ: 0, scale: 0.9, rotate: 0, zIndex: 0, isGoback: false},
      {url: '/images/5.png', translateX: 0, translateY: 32, translateZ: 0, scale: 0.9, rotate: 0, zIndex: 0, isGoback: false},
      {url: '/images/6.png', translateX: 0, translateY: 32, translateZ: 0, scale: 0.9, rotate: 0, zIndex: 0, isGoback: false},
      {url: '/images/7.png', translateX: 0, translateY: 32, translateZ: 0, scale: 0.9, rotate: 0, zIndex: 0, isGoback: false},
      {url: '/images/8.png', translateX: 0, translateY: 32, translateZ: 0, scale: 0.9, rotate: 0, zIndex: 0, isGoback: false},
    ],
    curX: 0,
    curY: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (opt) {
    // this.getBarHeight()
    // this.setListHeight()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},

  /**
   * 设置导航栏高度
   */
  getBarHeight() {
    let systemInfo = wx.getSystemInfoSync()
    console.log(systemInfo)
    let	statusBarHeight = systemInfo.statusBarHeight
    let menu = wx.getMenuButtonBoundingClientRect()

    let	barMarginTop = menu.top
    let	barHeight = menu.height + 10
    let barWidth = systemInfo.windowWidth - (systemInfo.windowWidth - menu.right + menu.width)

    this.setData({
      barMarginTop: barMarginTop,
      barHeight: barHeight,
      barWidth: barWidth
    })
  },

  /**
   * 设置scroll-view高度
   */
  setListHeight() {
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      hei = parseInt(this.data.barMarginTop) + parseInt(this.data.barHeight) + 4,
      tapHeight = Math.floor(rpx * hei * 2), // tap高度
      scrollHeight = systemInfo.windowHeight - tapHeight; // swiper高度
    this.setData({
      scrollHeight
    });
  },

  viewTouchstart(e) {
    let curX = e.touches[0].pageX
    let curY = e.touches[0].pageY

    this.setData({
      curX,
      curY,
    })
  },
  viewTouchend(e) {
    let _this = this
    let item = {url: '/images/1.png', translateX: 0, translateY: 0, translateZ: -50, scale: 1, rotate: 0, zIndex: 4, isGoback: false}
    _this.setData({
      'list[0].isGoback': true,
      // 'list[0].translateX': 0,
      // 'list[0].translateY': 0,
      // 'list[0].translateZ': -50,
      // 'list[0].scale': 1,
      // 'list[0].rotate': 0,
    })
    setTimeout(function(){
      _this.setData({
        'list[0].translateX': 0,
        'list[0].translateY': 0,
        'list[0].translateZ': -50,
        'list[0].scale': 1,
        'list[0].rotate': 0,
      })
      console.log(_this.data.list)
    }, 1200)
  },
  viewTouchMove(e) {
    console.log(e)
    let moveX = e.touches[0].pageX
    let moveY = e.touches[0].pageY
    let curX = this.data.curX
    let curY = this.data.curY
    let curRotate = 0
    let deg = moveX - curX
    console.log(deg)

    if(deg > 0) {
      // 右
      if(deg <= 18) {
        curRotate = 1
      } else if(deg > 19 && deg < 22) {
        curRotate = 2
      } else if(deg > 23 && deg < 25) {
        curRotate = 3
      } else if(deg > 26) {
        curRotate = 4
      }
    } else {
      // 左
      if(deg >= -18) {
        curRotate = -1
      } else if(deg < -19 && deg > -22) {
        curRotate = -2
      } else if(deg < -23 && deg > -25) {
        curRotate = -3
      } else if(deg < -26) {
        curRotate = -4
      }
    }

    this.setData({
      'list[0].translateX': moveX - curX,
      'list[0].translateY': moveY - curY,
      'list[0].rotate': curRotate,
    })
  },
})